package com.imranstechnology.homeexpensemanager;

import java.io.Serializable;
import java.text.NumberFormat;
import java.util.Date;
import java.util.Locale;

import com.imranstechnology.homeexpensemanager.utils.DateUtil;
import com.imranstechnology.homeexpensemanager.utils.StringUtil;

public class ExpenseDetailEntity implements Serializable{
	/**
	 * 
	 */
	private static final long serialVersionUID = -1690704704221009206L;
	private static final String RECORD_TEMPLATE = "%s;%s;%s;%f";
	private Long id;
	private Date transactionDate;
	private Integer expenseCategory;
	private Float expenseAmount;
	public ExpenseDetailEntity(Long id, Date transactionDate,
			Integer expenseCategory, Float expenseAmount) {
		super();
		this.id = id;
		this.transactionDate = transactionDate;
		this.expenseCategory = expenseCategory;
		this.expenseAmount = expenseAmount;
	}
	public ExpenseDetailEntity() {
		super();
	}
	public Long getId() {
		return id;
	}
	public void setId(Long id) {
		this.id = id;
	}
	public Date getTransactionDate() {
		return transactionDate;
	}
	public void setTransactionDate(Date transactionDate) {
		this.transactionDate = transactionDate;
	}
	public Integer getExpenseCategory() {
		return expenseCategory;
	}
	public void setExpenseCategory(Integer expenseCategory) {
		this.expenseCategory = expenseCategory;
	}
	public Float getExpenseAmount() {
		return expenseAmount;
	}
	public void setExpenseAmount(Float expenseAmount) {
		this.expenseAmount = expenseAmount;
	}
	
	@Override
	public String toString() {
		return String.format(RECORD_TEMPLATE, this.id,DateUtil.dateToString(this.transactionDate, DateUtil.STORE_DATE_FORMAT),this.expenseCategory,this.expenseAmount);
	}
	public static ExpenseDetailEntity parseExpenseDetailRecord(String record){
		ExpenseDetailEntity expEntity = null;
		
		String fields[] = record.split(ExpenseMemStore.RECORD_SEPERATOR);
		if(fields.length == 4)
		{
			Float value = 0f;
			
				value = StringUtil.parseStringFloat(fields[3]);
				expEntity = new ExpenseDetailEntity(Long.parseLong(fields[0]),DateUtil.stringToDate(fields[1], DateUtil.STORE_DATE_FORMAT),Integer.parseInt(fields[2]),value);
		}
		return expEntity;
	}
}
